package com.example.aboutwork.this_use;


import lombok.EqualsAndHashCode;
import org.junit.Test;
//一定要重写equals hashCode方法
@EqualsAndHashCode
public class ThisUse implements Runnable {

    private int num;

    @Override
    public void run() {
        System.err.println(ThisUse.this.num);
    }


    @Test
    public void testThisUse() {
        ThisUse thisUse = new ThisUse();
        System.err.println(thisUse.toString());
        System.err.println(ThisUse.this.toString());
        //这里可以发现thisUse与ThisUse.this是相等的
        // 正因为这样的原因 所以在run方法里 才得以能够与thisUse.num=i 相照应
        assert thisUse.equals(ThisUse.this);
    }

    @Test
    public void testThisUse1() {
        ThisUse thisUse = new ThisUse();
        for (int i = 0; i < 10; i++) {
            thisUse.num=i;
            thisUse.run();
        }
    }
}
